//
// Created by Tunm-Air13 on 2024/3/14.
//

#ifndef SIMPLESEMANTIC_SEMANTIC_CLS_H
#define SIMPLESEMANTIC_SEMANTIC_CLS_H

#include <iostream>
#include "memory"
#include "cppjieba/Jieba.hpp"
#include "fasttext/fasttext.h"
#include "configuration.h"
#include <fstream>
#include "basic_def.h"

namespace solex {

inline bool checkFileExists(const std::string& path) {
    std::ifstream file(path);
    return file.good();
}

class SemanticCls {
public:

    typedef struct {
        int32_t idx;                    // Classification index
        Sentence label;                 // English label
        Sentence labelCh;               // Chinese label
        Sentence cutResult;             // Last sentence of cut is separated by /
        Words cutWords;                 // Cut every word
        float probability;               // Classification probability
    } SemanticPredictResult;

public:

    SemanticCls();

    int32_t Initialization(const std::string &folderPath);

    int32_t Predict(const Sentence &sentence, SemanticPredictResult& output);

private:

    Indexes getWordsIds(Words &words);

    Words cut(const Sentence &semantic);


private:

    bool m_use_hmm_ = true;

    std::shared_ptr<fasttext::FastText> m_interpreter_;

    std::shared_ptr<cppjieba::Jieba> m_jieba_;

};

}   // namespace solex

#endif //SIMPLESEMANTIC_SEMANTIC_CLS_H
